package com.ruoyi.web.controller.base;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PropertyFacilityMaintain;
import com.ruoyi.system.service.IPropertyFacilityMaintainService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设施维护记录Controller
 * 
 * @author ruoyi
 * @date 2025-10-27
 */
@RestController
@RequestMapping("/system/maintain")
public class PropertyFacilityMaintainController extends BaseController
{
    @Autowired
    private IPropertyFacilityMaintainService propertyFacilityMaintainService;

    /**
     * 查询设施维护记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:maintain:list')")
    @GetMapping("/list")
    public TableDataInfo list(PropertyFacilityMaintain propertyFacilityMaintain)
    {
        startPage();
        List<PropertyFacilityMaintain> list = propertyFacilityMaintainService.selectPropertyFacilityMaintainList(propertyFacilityMaintain);
        return getDataTable(list);
    }

    /**
     * 导出设施维护记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:maintain:export')")
    @Log(title = "设施维护记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PropertyFacilityMaintain propertyFacilityMaintain)
    {
        List<PropertyFacilityMaintain> list = propertyFacilityMaintainService.selectPropertyFacilityMaintainList(propertyFacilityMaintain);
        ExcelUtil<PropertyFacilityMaintain> util = new ExcelUtil<PropertyFacilityMaintain>(PropertyFacilityMaintain.class);
        util.exportExcel(response, list, "设施维护记录数据");
    }

    /**
     * 获取设施维护记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:maintain:query')")
    @GetMapping(value = "/{maintainId}")
    public AjaxResult getInfo(@PathVariable("maintainId") Long maintainId)
    {
        return success(propertyFacilityMaintainService.selectPropertyFacilityMaintainByMaintainId(maintainId));
    }

    /**
     * 新增设施维护记录
     */
    @PreAuthorize("@ss.hasPermi('system:maintain:add')")
    @Log(title = "设施维护记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PropertyFacilityMaintain propertyFacilityMaintain)
    {
        return toAjax(propertyFacilityMaintainService.insertPropertyFacilityMaintain(propertyFacilityMaintain));
    }

    /**
     * 修改设施维护记录
     */
    @PreAuthorize("@ss.hasPermi('system:maintain:edit')")
    @Log(title = "设施维护记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PropertyFacilityMaintain propertyFacilityMaintain)
    {
        return toAjax(propertyFacilityMaintainService.updatePropertyFacilityMaintain(propertyFacilityMaintain));
    }

    /**
     * 删除设施维护记录
     */
    @PreAuthorize("@ss.hasPermi('system:maintain:remove')")
    @Log(title = "设施维护记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{maintainIds}")
    public AjaxResult remove(@PathVariable Long[] maintainIds)
    {
        return toAjax(propertyFacilityMaintainService.deletePropertyFacilityMaintainByMaintainIds(maintainIds));
    }
}
